
#include<stdio.h>
int *l,q;


int append(int *l)
{
   int x,i;
   printf("Enter the element to be appended\n");
scanf("%d",&x);
//l[n]=malloc(sizeof(int)); 
q++;      //use realloc
l[q-1]=x;
l=(int*)(realloc(l,(sizeof(int)*q)));   ///////////

printf("array :\n");
for (i=0;i<q+1;i++)
{
printf("%d ",l[i]);
}}



int reverse(int *l)
{
int i;
printf(" array :\n");
for (i=q-1;i>=0;i--)
{
printf("%d ",l[i]);
}
}




int inde(int *l)
{
int   z,i;
printf("Enter the no. whose 1st position you want to know:\n");
scanf("%d",&z);

for(i=0;i<q;i++)
{
	
  if(l[i]==z)
{
	
	printf("%d ",i);
	break;
	}
}
}





int insert(int *l)
{
int z,p;
printf("Enter the position where u want to insert:\n");
scanf("%d",&z);
q++;
/*increase size  +1  */
l=(int*)(realloc(l,(sizeof(int)*q)));   //////////
for(int i=q;i>z;i--)
{
l[i]=l[i+1];
}

printf("Enter the number u want to insert:\n");
scanf("%d",&p);

l[z-1]=p;

printf("array is:\n");
for (i=0;i<q+1;i++)
printf("%d ",l[i]);
}





int count(int *l)
{
int i,z,count=0;
printf("Enter the element you want to check for no. of occurences:\n");
scanf("%d",&z);

for(i=0;i<q;i++)
{
if(l[i]==z)
{
count+=1;
}}

printf("No of occurences=%d",count);

}




int remove1(int *l)
{
int i,z,c;
printf("Enter the element you want to remove once:\n");
scanf("%d",&z);

for(i=0;i<q;i++)
{

if(l[i]==z)
{
c=i;                           /*c is the position*/
break;
}}

for(i=c;i<q-1;i++)
{l[i]=l[i+1];
}


printf("Final Array:\n");
for (i=0;i<q-1;i++)
{
printf("%d",l[i]);
}


q--;
l=(int*)(realloc(l,(sizeof(int)*q)));        /////
}


int pop(int *l)
{
int i,z,j;
printf("Enter the position:\n");
scanf("%d",&z);
len--;
a=(int*)(realloc(l,(sizeof(int)*q)));        /////////////

for(j=z;j<=q-1;j++)
{
a[j]=a[j+1];
}

printf("Final Array is:");
for (i=0;i<q;i++)
{
printf("%d ",l[i]);
}
}













#include<stdio.h>

void main()
{


int i,n;
printf("enter length");
scanf("%d",&q);
l=malloc(sizeof(int)*q);

for (i=0;i<q;i++)
{
printf("Enter the elements\n");
scanf("%d",&l[i]);
}

printf("1=append 2=sort 3=reverse 4=index 5=insert 6=count 7=remove 8=pop \n");

printf("Enter the choice :");
scanf("%d",&n);


switch(n){
case 1: append(l,q);
	break;
case 2: sort(l);
	break;
case 3: reverse(l,q);
	break;
case 4:inde(l,q);
	break;
case 5: insert(l,q);
	break;
case 6: count(l,q);
	break;
case 7: removeq(l,q);
	break;
case 8: pop(l,q);
	break;

}


}
